package com.bh.ly.oa.activity;

import java.util.Calendar;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.DatePicker.OnDateChangedListener;

import com.bh.ly.oa.R;

public class SearchGoodsSaleDeptDtlActivity extends Activity{
	
	private EditText order_number;
	private DatePicker startdate;
	private DatePicker enddate;
	private String start_date;
	private String end_date;

	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.reseach_goods_saledept_view);
		ImageButton button = (ImageButton) findViewById(R.id.back_button);
		Button btn=(Button)findViewById(R.id.forward_button);
		button.setVisibility(View.VISIBLE);
		btn.setVisibility(View.VISIBLE);
		btn.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {
				forwardtoOrderActivity();
			}
		});
		button.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				finish();
			}
		});
		
		startdate=(DatePicker)findViewById(R.id.start_date);
		enddate=(DatePicker)findViewById(R.id.end_date); 
        Calendar calendar=Calendar.getInstance();
        int year=calendar.get(Calendar.YEAR);
        int monthOfYear=calendar.get(Calendar.MONTH);
        int dayOfMonth=calendar.get(Calendar.DAY_OF_MONTH);
        
        start_date = year+"-"+(monthOfYear+1)+"-"+dayOfMonth;
        end_date = start_date;
        
        startdate.init(year, monthOfYear, dayOfMonth, new OnDateChangedListener(){

			@Override
			public void onDateChanged(DatePicker view, int year,
					int monthOfYear, int dayOfMonth) {
				start_date=year+"-"+(monthOfYear+1)+"-"+dayOfMonth;
			}
        	
        });
        enddate.init(year, monthOfYear, dayOfMonth, new OnDateChangedListener(){

			@Override
			public void onDateChanged(DatePicker view, int year,
					int monthOfYear, int dayOfMonth) {
				end_date=year+"-"+(monthOfYear+1)+"-"+dayOfMonth;
			}
        	
        });
	}	
	
	private void forwardtoOrderActivity() {
		order_number=(EditText)findViewById(R.id.order_number);
		Intent intent=getIntent();
		intent.putExtra("deptcode", order_number.getText().toString());
		intent.putExtra("startdate", start_date);
		intent.putExtra("enddate", end_date);
		setResult(1, intent);
		finish();
	}
}
